//
//  nodeset.cpp
//  cobalt
//
//  Created by Nicolas Godbout on 2013-08-31.
//  Copyright (c) 2013 Nicolas Godbout. All rights reserved.
//

#include "nodeset.h"

namespace rdf {
    
    const Node
    NodeSet::emptyNode {};
    
    Node const&
    NodeSet::lookupNamedNode(const std::string &uri) const noexcept {
        namedSet_t::const_iterator node = namedSet.find(Node(internal::NamedNode(uri)));
        if ( node == namedSet.cend() )
            return emptyNode;
        else
            return *node;
    }
    
    Node const&
    NodeSet::lookupLiteral(const std::string &value,
                           const std::string &lang,
                           const rdf::Node &datatype) const noexcept {
        if ( datatype.interfaceName() != co::NamedNode )
            return emptyNode;
        literalSet_t::const_iterator node =
        literalSet.find(Node(internal::Literal(value, lang,
                                               std::static_pointer_cast<internal::NamedNode>(datatype.node))));
        if ( node == literalSet.cend() )
            return emptyNode;
        else
            return *node;
    }
    
    void
    NodeSet::insertNode(rdf::Node&& node) noexcept {
        if ( node.interfaceName() == co::NamedNode ) {
            auto res = namedSet.insert(node);
            if ( res.second )
        }
    }
    
}